/**
 * 
 */
package org.bookie.model;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.validator.NotNull;

/**
 * Class modelling a wager.
 * 
 * @author Igor Drobiazko
 */
@Entity
@Table(name="Wagers")
public class Wager extends CommonEntity {
	private static final long serialVersionUID = 1L;

	/** Outcome this Bet belongs to */
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="OUTCOME_ID")
    @NotNull
	private Outcome outcome;
    
	/** BetSlip this Bet belongs to */
    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="BETSLIP_ID")
    @NotNull
    private BetSlip betSlip;

	/** Odds of the Wager to become the outcome */
    @Basic @NotNull private Double odds;

	/** Constructs an empty instance of the Wager */
	protected Wager() {super();}

	/**
	 * Constructs a new instance of Wager
	 * 
	 * @param label label to set
	 */
	public Wager(Outcome outcome) {
		this.outcome=outcome;
		this.odds = outcome.getOdds();
	}
	
	/**
	 * Shortcut for <code>getOutcome().isSuccessful()</code>
	 */
	public boolean isSuccessful(){
		return outcome.isSuccessful();
	}

	/**
	 * Returns the odds of the Wager
	 */
	public Double getOdds() {
		return odds;
	}

	/**
	 * Set the odds of the Bet 
	 * @param odds odds to set
	 */
	public void setOdds(Double odd) {
		this.odds = odd;
	}
	/**
	 * Returns the corresponding {@link Outcome}
	 */
	public Outcome getOutcome() {
		return outcome;
	}
	
	public void setOutcome(Outcome outcome) {
		this.outcome = outcome;
	}

	public BetSlip getBetSlip() {
		return betSlip;
	}

	public void setBetSlip(BetSlip betSlip) {
		this.betSlip = betSlip;
	}

}
